/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.d2g.realestate.webservice.client;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;

/** Jersey REST client generated for REST resource:ExchangeRateSoapWebServicePort [exchangeratesoapwebserviceport]<br>
 *  USAGE:<pre>
 *        ExchangeRateRestWSClient client = new ExchangeRateRestWSClient();
 *        Object response = client.XXX(...);
 *        // do whatever with response
 *        client.close();
 *  </pre>
 * @author d2g
 */
public class ExchangeRateRestWSClient {
    private WebResource webResource;
    private Client client;
    private static final String BASE_URI = "http://localhost:8080/ExchangeRate/resources";

    public ExchangeRateRestWSClient() {
        com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig();
        client = Client.create(config);
        webResource = client.resource(BASE_URI).path("exchangeratesoapwebserviceport");
    }

    public <T> T getFindAll(Class<T> responseType) throws UniformInterfaceException {
        WebResource resource = webResource;
        resource = resource.path("findall");
        return resource.accept(javax.ws.rs.core.MediaType.APPLICATION_XML).get(responseType);
    }

    public <T> T postFindRange(Class<T> responseType, Object requestEntity) throws UniformInterfaceException {
        return webResource.path("findrange").type(javax.ws.rs.core.MediaType.APPLICATION_XML).post(responseType, requestEntity);
    }

    public <T> T postFind(Class<T> responseType, Object requestEntity) throws UniformInterfaceException {
        return webResource.path("find").type(javax.ws.rs.core.MediaType.APPLICATION_XML).post(responseType, requestEntity);
    }

    public void putEdit(Object requestEntity) throws UniformInterfaceException {
        webResource.path("edit").type(javax.ws.rs.core.MediaType.APPLICATION_XML).put(requestEntity);
    }

    public void putCreate(Object requestEntity) throws UniformInterfaceException {
        webResource.path("create").type(javax.ws.rs.core.MediaType.APPLICATION_XML).put(requestEntity);
    }

    public <T> T getSearchRateToGBP(Class<T> responseType, String currency) throws UniformInterfaceException {
        WebResource resource = webResource;
        if (currency != null) {
            resource = resource.queryParam("currency", currency);
        }
        resource = resource.path("searchratetogbp");
        return resource.accept(javax.ws.rs.core.MediaType.APPLICATION_XML).get(responseType);
    }

    public void putRemove(Object requestEntity) throws UniformInterfaceException {
        webResource.path("remove").type(javax.ws.rs.core.MediaType.APPLICATION_XML).put(requestEntity);
    }

    public String getCount() throws UniformInterfaceException {
        WebResource resource = webResource;
        resource = resource.path("count");
        return resource.accept(javax.ws.rs.core.MediaType.TEXT_PLAIN).get(String.class);
    }

    public void close() {
        client.destroy();
    }
    
}
